package com.yixun.lbx.service.impl;

import com.yixun.lbx.entity.YxProBreedDisinfect;
import com.yixun.lbx.mapper.farm.BreedDisinfectMapper;
import com.yixun.lbx.service.BreedDisinfectService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BreedDisinfectServiceImpl implements BreedDisinfectService {
    private final BreedDisinfectMapper disinfectMapper;

    public BreedDisinfectServiceImpl(BreedDisinfectMapper disinfectMapper) {
        this.disinfectMapper = disinfectMapper;
    }

    @Override
    public Integer getCount(HashMap<String, Object> map) {
        return disinfectMapper.getCount(map);
    }

    @Override
    public List<YxProBreedDisinfect> getListByPage(HashMap<String, Object> map) {
        return disinfectMapper.getListByPage(map);
    }

    @Override
    public int addDisinfect(HashMap<String, Object> map) {
        map.put("addTime", getDate());
        return disinfectMapper.insertSelective(map);
    }

    @Override
    public int updateDisinfect(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return disinfectMapper.updateByPrimaryKeySelective(map);
    }

    @Override
    public int deleteDisinfect(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return disinfectMapper.deleteByPrimaryKey(map);
    }

    @Override
    public List<YxProBreedDisinfect> getObjByArgs(YxProBreedDisinfect disinfect) {
        return disinfectMapper.getObjByArgs(disinfect);
    }

    @Override
    public List<YxProBreedDisinfect> getSearchListByPage(HashMap<String, String> map) {
        return disinfectMapper.getSearchListByPage(map);
    }

    private String getDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }
}
